package com.group01.web.controller;

import com.group01.annotation.SystemLog;
import com.group01.dto.Admin.AdminLoginDTO;
import com.group01.dto.User.RegisterDTO;
import com.group01.dto.User.UserUpdateInfoDTO;
import com.group01.dto.User.UserUpdatePassDTO;
import com.group01.result.Result;
import com.group01.service.AdminService;
import com.group01.service.UserService;
import com.group01.vo.Admin.AdminLoginVO;
import com.group01.vo.User.UserGetInfoByIdVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description
 * @Author 翟玉龙
 * @Date 2024/6/22
 */
@RestController
@RequestMapping("/user")
@Validated
@Api(tags = "认证 + 用户模块")
public class UserController {

    /**
     * 注入
     */
    private final UserService userService;
    private final AdminService adminService;

    public UserController(UserService userService,AdminService adminService) {
        this.userService = userService;
        this.adminService = adminService;
    }

    /**
     * 注册用户
     * @param registerDTO 用户信息DTO
     * @return {@link Result }<{@link String }>
     */
    @ApiOperation("注册用户")
    @PostMapping("/register")
    public Result<String> registerUser(@Validated @RequestBody RegisterDTO registerDTO) {
        return userService.register(registerDTO);
    }

    /**
     * 获取用户信息
     * @return {@link Result }<{@link UserGetInfoByIdVO }>
     */
    @ApiOperation("获取用户信息")
    @GetMapping("/getUserInfo")
    public Result<UserGetInfoByIdVO> getUserInfo() {
        return userService.getUserInfo();
    }

    /**
     * 登录用户
     * @param userLoginDTO 用户信息DTO
     * @return {@link Result }<{@link AdminLoginVO }>
     */
    @ApiOperation("登录用户")
    @PostMapping("/login")
    public Result<AdminLoginVO> loginUser(@Validated @RequestBody AdminLoginDTO userLoginDTO) {
        return adminService.loginUser(userLoginDTO);
    }

    /**
     * 修改密码
     * @param userUpdatePassDTO 用户信息DTO
     * @return {@link Result }<{@link String }>
     */
    @ApiOperation("修改密码")
    @PutMapping("/updatePassword")
    public Result<String> updatePassword(
            @RequestBody @Validated UserUpdatePassDTO userUpdatePassDTO
    ) {
        return userService.updatePassword(userUpdatePassDTO);
    }

    /**
     * 修改用户信息
     * @param updateInfoDTO 用户信息DTO
     * @return {@link Result }<{@link UserGetInfoByIdVO }>
     */
    @ApiOperation("修改用户信息")
    @PutMapping("/updateUser")
    public Result<UserGetInfoByIdVO> updateUser(@Validated @RequestBody UserUpdateInfoDTO updateInfoDTO) {
        return userService.updateUserInfo(updateInfoDTO);
    }

    /**
     * 用户退出
     * @return {@link Result }<{@link String }>
     */
    @PostMapping("/logout")
    public Result<String> UserLogout() {
        return adminService.logoutAdmin();
    }
}
